package com.kongchengji.zhanguafou.utils;

import com.alibaba.fastjson.JSONObject;
import com.kongchengji.zhanguafou.constant.WxInfo;
import com.kongchengji.zhanguafou.domain.AccessTokenDO;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;
import java.util.List;

public class UserOpenIdUtil {
    public static List<String> getOpenId() throws IOException {
        AccessTokenDO accessToken = WxInfo.accessToken;
        Request request = new Request.Builder()
                .url("https://api.weixin.qq.com/cgi-bin/user/get?access_token="+accessToken.getToken())
                .build();
        OkHttpClient client = new OkHttpClient();
        Response response = client.newCall(request).execute();
        JSONObject reply = JSONObject.parseObject(response.body().string());
        JSONObject data = (JSONObject) reply.get("data");
        List<String> openIds = (List<String>) data.get("openid");
        return openIds;
    }
}
